/*
 * @Author: i@douxuefeng.cn
 * @Date: 2022-04-12 15:14:20
 * @LastEditTime: 2022-04-12 15:27:01
 * @LastEditors: i@douxuefeng.cn
 * @Description:
 * @FilePath: \go-wechat\pay\refund\reund.go
 */
package refund

import (
	"gitee.com/douxuefeng/go-wechat/pay/config"
	"gitee.com/douxuefeng/go-wechat/pay/tools"
	"github.com/wechatpay-apiv3/wechatpay-go/core"
	"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
)

type refund struct {
	*config.PayConfig
}

func NewRefund(cfg *config.PayConfig) *refund {
	return &refund{cfg}
}

func (p *refund) Create(ref refunddomestic.CreateRequest) (*refunddomestic.Refund, *core.APIResult, error) {
	client, ctx, err := tools.GetClient(p.PayConfig)
	if err != nil {
		return nil, nil, err
	}
	svc := refunddomestic.RefundsApiService{Client: client}
	resp, result, err := svc.Create(ctx, ref)
	return resp, result, err
}
